<?php
/**
 * Custom Front Controller Resource. Since every project may have a specific auth / acl, that
 * class is still in the skeleton so devs can modify it up to their needs.
 */
class Application_Resource_Frontcontroller extends Zend_Application_Resource_Frontcontroller
{
    /**
     * Initialize Front Controller and assign plugins that can't be assigned using application.ini
     *
     * @return Zend_Controller_Front
     */
    public function init()
    {
        $this->getBootstrap()->bootstrap('acl');
        $front = parent::init();

        // Register Auth plugin, as we need to give it the $acl
        // we can't rely on pure Zend_Application_Resource_Frontcontroller / config only
        $acl = $this->getBootstrap()->getResource('acl');

        require_once 'Application/Controller/Plugin/Auth.php';
        $plugin = new Application_Controller_Plugin_Auth($acl);
        $front->registerPlugin($plugin, 1); // Give it a low stack index
        $front->registerPlugin(new BRail_Application_Controller_Plugin_CsrfProtection(), 2);
        $front->setParam('bootstrap', $this->getBootstrap());
        return $front;
    }
}